// 获取实况天气
const getNowWeather = async (locationId) => {
    const [error, res] = await uni.request({
        url: 'https://devapi.heweather.net/v7/weather/now?',
        method: 'GET',
        data: {
            location: locationId,
            key: '54a354134662428c98ec7dfbe52531d1',
        }
    });
    return res.data
}
// 获取7天内天气 天气预报
const get3dayWeather = async (locationId) => {
    const [error, res] = await uni.request({
        url: 'https://devapi.heweather.net/v7/weather/3d?',
        method: 'GET',
        data: {
            location: locationId,
            key: '54a354134662428c98ec7dfbe52531d1',
        }
    });
    return res.data
}

// 未来24小时
const get24HWeather = async (locationId) => {
    const [error, res] = await uni.request({
        url: 'https://devapi.heweather.net/v7/weather/24h?',
        method: 'GET',
        data: {
            location: locationId,
            key: '54a354134662428c98ec7dfbe52531d1',
        }
    });
    return res.data
}

// 灾害预警城市列表
const warnList = async () => {
    const [error, res] = await uni.request({
        url: 'https://devapi.heweather.net/v7/warning/list?',
        method: 'GET',
        data: {
            range: 'cn',
            key: '54a354134662428c98ec7dfbe52531d1',
        }
    });
    return res.data
}

// 预警信息
const warnInfo = async (locationId) => {
    const [error, res] = await uni.request({
        url: 'https://devapi.heweather.net/v7/warning/now?',
        method: 'GET',
        data: {
            location: locationId,
            key: '54a354134662428c98ec7dfbe52531d1',
        }
    })
    return res.data
}

// 热门城市列表查询
const hotCitylist = async () => {
    const [error, res] = await uni.request({
        url: 'https://geoapi.heweather.net/v2/city/top?',
        method: 'GET',
        data: {
            range: 'cn',
            key: '54a354134662428c98ec7dfbe52531d1',
            number: 6
        }
    })
    return res.data
}

// 城市信息查询
const cityInfo = async (location) => {
    const [error, res] = await uni.request({
        url: 'https://geoapi.heweather.net/v2/city/lookup?',
        method: 'GET',
        data: {
            location: location,
            range: 'cn',
            key: '54a354134662428c98ec7dfbe52531d1',
            number: 6
        }
    })
    return res.data
}

// 当天生活指数
const indiceToday = async (location) => {
    const [error, res] = await uni.request({
        url: 'https://devapi.heweather.net/v7/indices/1d?',
        method: 'GET',
        data: {
            location: location,
            key: '54a354134662428c98ec7dfbe52531d1',
            type: '1,2,3,5,8,9',

        }
    })
    return res.data
}

module.exports = {
    cityInfo, hotCitylist, warnInfo, warnList, get24HWeather, get3dayWeather, getNowWeather, indiceToday
}